    //
//  DishFlavor.m
//  Menu
//
//  Created by trimad on 11-11-24.
//  Copyright 2011 Trimad Group. All rights reserved.
//

#import "DishFlavor.h"
#import "Util.h"
#import "OrderItem.h"


@implementation DishFlavor

@synthesize tableData;
@synthesize tableView;
@synthesize comments;
@synthesize itemCode;
@synthesize dishNameLabel;
@synthesize itemArray;

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil item:(NSString *)dishCode {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
		self.itemCode=dishCode;
    }
    return self;
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	[tableView setBackgroundColor:[UIColor clearColor]];
	tableData = [[NSArray alloc] 
				 initWithObjects: @"免姜",@"免辣",@"免蒜",@"免葱",@"免香菜",@"免糖",nil];
	NSMutableDictionary *tempDic=[Util readFileForDictionary:@"localOrderData"];
	itemArray=[tempDic objectForKey:self.itemCode];
	
	dishNameLabel.text=[[itemArray objectAtIndex:0] stringByAppendingString:@" /"];
	comments.text=[itemArray objectAtIndex:4];
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

#pragma mark -
#pragma mark Table View Data Source Methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
	return [self.tableData count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 1;
}

- (UITableViewCell *)tableView:(UITableView *)uiTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *SimpleTableIdentifier = @"DishFlavorTableIdentifier";
	UITableViewCell *cell = [uiTableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle
									  reuseIdentifier:SimpleTableIdentifier] autorelease];
	}
	NSUInteger row1=[indexPath row];
	NSString *option=[[self.tableData objectAtIndex:row1] stringByAppendingString:@"      "];
	cell.textLabel.text=option;
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
	NSUInteger row1=[indexPath row];
	
	NSRange range=[[self.comments text] rangeOfString:[tableData objectAtIndex:row1]];
	if (range.location != NSNotFound) {
		return;
	}
	
	NSString *option=@"";
	option=[option stringByAppendingString:[self.comments text]];
	option=[option stringByAppendingString:[tableData objectAtIndex:row1]];
	option=[option stringByAppendingString:@","];
	self.comments.text=option;
}

- (IBAction)backToOderSummary:(id)sender{
	NSLog(@"backToOderSummary");
	if (itemArray != nil) {
		[self.itemArray replaceObjectAtIndex:4 withObject:self.comments.text];
		NSMutableDictionary *tempDic=[Util readFileForDictionary:@"localOrderData"];
		[tempDic setObject:self.itemArray forKey:self.itemCode];
		[Util writeFileForDictionary:tempDic:@"localOrderData"];
	}
	
	[self.view removeFromSuperview]; 
}


@end
